		TITLE PUTGROUP - Copyright (c) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	SEGMENTS
		INCLUDE	GROUPS
		INCLUDE	CLASSES

		PUBLIC	PUT_SM_IN_GROUP


		.DATA

		EXTERNDEF	BUFFER_OFFSET:DWORD,DGROUP_GINDEX:DWORD

		EXTERNDEF	CLASS_GARRAY:STD_PTR_S,SEGMENT_GARRAY:STD_PTR_S,SEGMOD_GARRAY:STD_PTR_S,GROUP_GARRAY:STD_PTR_S


		.CODE	PASS1_TEXT

		EXTERNDEF	WARN_ASCIZ_RET:PROC,ERR_ASCIZ_RET:PROC

		EXTERNDEF	DUP_GROUP_ERR:ABS,GRP_TYP_ERR:ABS


PUT_SM_IN_GROUP	PROC
		;
		;EDX IS GROUP GINDEX
		;EAX IS SEGMOD GINDEX
		;CL    IS GROUP_TYPE
		;
		PUSH	ESI
		CONVERT	EAX,EAX,SEGMOD_GARRAY
		MOV	ESI,[EAX].SEGMOD_STRUCT._SM_BASE_SEG_GINDEX

		MOV	EAX,ESI
		CONVERT	ESI,ESI,SEGMENT_GARRAY
		ASSUME	ESI:PTR SEGMENT_STRUCT
		;
		;FIRST, GROUP MUST BE ZERO OR MATCH, USUALLY A MATCH
		;
		CMP	[ESI]._SEG_GROUP_GINDEX,EDX
		JNZ	L1$

		POP	ESI
		RET

L1$:
		PUSH	EBX
		MOV	EBX,ECX

		MOV	EAX,[ESI]._SEG_GROUP_GINDEX
		MOV	BH,[ESI]._SEG_TYPE

		TEST	EAX,EAX
		JNZ	ERROR_GROUP			;ALREADY IN OTHER GRP

		AND	BH,MASK SEG_RELOC + MASK SEG_ASEG
		MOV	[ESI]._SEG_GROUP_GINDEX,EDX

		;NOW, MUST DEFINE OR MATCH GROUP 'TYPE'

		CMP	BH,BL
		JNZ	SET_GROUP_TYPE
SET_GRP_RET:
		MOV	ECX,DGROUP_GINDEX
		MOV	AL,[ESI]._SEG_TYPE

		CMP	ECX,EDX
		JNZ	DONE_GROUP
		;
		;IF SEGMENT NOT ALREADY MARKED, MARK IT AND ANY SEGMODS.
		;
		TEST	AL,MASK SEG_IN_DGROUP
		JNZ	DONE_GROUP

		OR	AL,MASK SEG_IN_DGROUP
		MOV	ECX,[ESI]._SEG_CLASS_GINDEX		;MARK ITS CLASS ALSO

		MOV	[ESI]._SEG_TYPE,AL
		MOV	EAX,[ESI]._SEG_FIRST_SEGMOD_GINDEX

		CONVERT	ECX,ECX,CLASS_GARRAY
		ASSUME	ECX:PTR CLASS_STRUCT
		OR	[ECX]._C_TYPE_FLAG,MASK SEG_IN_DGROUP
		JMP	L35$

L3$:
		CONVERT	EAX,EAX,SEGMOD_GARRAY
		ASSUME	EAX:PTR SEGMOD_STRUCT

		OR	[EAX]._SM_FLAGS,MASK SEG_IN_DGROUP

		MOV	EAX,[EAX]._SM_NEXT_SEGMOD_GINDEX
L35$:
		TEST	EAX,EAX
		JNZ	L3$
DONE_GROUP:
		POPM	EBX,ESI

		RET

ERROR_GROUP:
		ASSUME	ESI:PTR SEGMENT_STRUCT

		MOV	AL,DUP_GROUP_ERR
		LEA	ECX,[ESI]._SEG_TEXT

		CALL	WARN_ASCIZ_RET

		POPM	EBX,ESI

		RET

SET_GROUP_TYPE:
		CONVERT	EAX,EDX,GROUP_GARRAY
		ASSUME	EAX:PTR GROUP_STRUCT

		OR	BL,BL
		JNZ	GRPTYP_ERROR

		MOV	[EAX]._G_TYPE,BH	;SET GROUP ASEG OR RELOC
		MOV	BL,BH

		JMP	SET_GRP_RET

GRPTYP_ERROR:
		LEA	ECX,[EAX]._G_TEXT
		MOV	AL,GRP_TYP_ERR

		CALL	ERR_ASCIZ_RET

		POPM	EBX,ESI

		RET

PUT_SM_IN_GROUP	ENDP


		END

